package 剑指offer;

import java.util.LinkedList;
import java.util.List;

public class _26树的子结构 {

     public class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode(int x) {
             val = x;
         }
     }
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A == null || B == null){
            return false;
        }
        return fun(A,B) || isSubStructure(A.right,B) || isSubStructure(A.left,B);

    }
    public boolean fun(TreeNode A, TreeNode B){
         if(B == null){
             return true;
         }else if(A == null || A.val != B.val){
             return false;
         }
        return fun(A.left,B.left) && fun(A.right,B.right);
    }
}
